// FactoryZTEC450.cpp: implementation of the CFactoryDCPowerChroma class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "FactoryZTEC450.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
//#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSCOPE_ZT_450* CFactoryZTEC450::m_instance = NULL;

CFactoryZTEC450::CFactoryZTEC450()
{
	m_Ref = 0;
}

CFactoryZTEC450::~CFactoryZTEC450()
{

}

HRESULT  CFactoryZTEC450::QueryInterface(const IID& iid, void **ppv)
{
	if ( iid == IID_IUnknown )
	{
		*ppv = (IUnknown *) this ;
		((IUnknown *)(*ppv))->AddRef() ;
	} else if ( iid == IID_IClassFactory) 
	{
		*ppv = (IClassFactory *) this ;
		((IClassFactory *)(*ppv))->AddRef() ;
	} 
	else
	{
		*ppv = NULL;
		return E_NOINTERFACE ;
		
	}
	return S_OK;
}

HRESULT CFactoryZTEC450::CreateInstance(IUnknown *pUnknownOuter, 
												 const IID& iid, void **ppv)
{
	HRESULT hr;
	   
	*ppv=NULL;
    hr=E_OUTOFMEMORY;
    if (NULL != pUnknownOuter)
		return CLASS_E_NOAGGREGATION;
	
	if(m_instance == NULL)
	{
		m_instance = new CSCOPE_ZT_450;
		if (NULL==m_instance)
			return hr; 
	}
	hr=m_instance->QueryInterface(iid, ppv);
	if (hr != S_OK) 
		delete m_instance;
	return hr;   
}

ULONG	  CFactoryZTEC450::AddRef()
{
	m_Ref ++;
	return  (ULONG) m_Ref;
}

ULONG	  CFactoryZTEC450::Release()
{
	m_Ref --;
	
	if (m_Ref == 0 ) {
		delete this;
		return 0;
	}
	return  (ULONG) m_Ref;
}

HRESULT CFactoryZTEC450::LockServer(BOOL bLock)
{
	return NOERROR;
}